<body></body>
<script>
function delay(ms) {
  return new Promise((resolve, reject) => {
    setTimeout(resolve, ms)
  })
}
const {body} = document
async function lights() {
  body.style.backgroundColor='red'
  await delay(3000)
  body.style.backgroundColor='yellow'
  await delay(1000)
  body.style.backgroundColor='green'
  await delay(3000)
  body.style.backgroundColor='yellow'
  await delay(1000)
  lights()

  // return delay(0)
  //   .then(() => body.style.backgroundColor='red')
  //   .then(() => delay(3000))
  //   .then(() => body.style.backgroundColor='yellow')
  //   .then(() => delay(1000))
  //   .then(() => body.style.backgroundColor='green')
  //   .then(() => delay(3000))
  //   .then(() => body.style.backgroundColor='yellow')
  //   .then(() => delay(1000))
  //   .then(() => lights())
}
lights()
</script>